
/*
 * Copyright (C) 2008-2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id$
 */

package org.dellroad.sidekar.datastore;

import java.util.HashSet;
import java.util.Set;

import org.dellroad.sidekar.Entity;
import org.dellroad.sidekar.Index;
import org.dellroad.sidekar.ListField;
import org.dellroad.sidekar.MapField;
import org.dellroad.sidekar.SetField;
import org.dellroad.sidekar.SimpleField;
import org.dellroad.sidekar.datastore.AbstractDatastore;
import org.dellroad.sidekar.datastore.Datastore;
import org.dellroad.sidekar.query.QueryList;
import org.dellroad.sidekar.query.QueryMap;
import org.dellroad.sidekar.query.QuerySet;
import org.dellroad.sidekar.schema.change.SchemaChange;
import org.dellroad.sidekar.schema.model.SchemaModel;

/**
 * A {@link Datastore} that wraps an inner {@link Datastore} and adds automated update tracking
 * for schema and data changes.
 *
 * <p>
 * Instances are configured with a set of {@link DatastoreUpdate}s. This class keeps track of which
 * updates have been aplied and ensures outstanding updates are applied automatically as necessary
 * and in an order consistent with their predecessor constraints. Once an update is applied, its name
 * is recorded in the underlying datastore.
 * </p>
 */
public class UpdatingDatastore extends AbstractDatastore {

    private final Datastore inner;
    private final HashSet<Datastore> updates;

    public UpdatingDatastore(Datastore inner, Set<DatastoreUpdate> updates) {
        this.inner = inner;
        this.updates = new HashSet<Datastore>(updates);
    }

    @Override
    protected void doDatastoreOpen() {
    }

    @Override
    protected void doDatastoreClose() {
        this.inner.datastoreClose();
    }

    @Override
    protected SchemaModel doSchemaRetrieve() {
        // TODO
    }

    @Override
    protected void doSchemaChange(SchemaChange change) {
    }

    @Override
    protected long doInstanceCreate(Entity<?> entity) {
        return this.inner.instanceCreate(entity);
    }

    @Override
    protected void doInstanceAttach(Entity<?> entity, long id) {
    }

    @Override
    protected void doInstanceDetach(Entity<?> entity, long id) {
    }

    @Override
    protected boolean doInstanceIsAttached(Entity<?> entity, long id) {
    }

    @Override
    protected <E> QuerySet<E> doEntityAccess(Entity<?> entity, boolean exact) {
    }

    @Override
    protected <T> T doSimpleFieldRead(Entity<?> entity, long id, SimpleField<T> field) {
    }

    @Override
    protected <T> void doSimpleFieldWrite(Entity<?> entity, long id, SimpleField<T> field, T value) {
    }

    @Override
    protected <E> QuerySet<E> doSetFieldAccess(Entity<?> entity, long id, SetField<E> field) {
    }

    @Override
    protected <K, V> QueryMap<K, V> doMapFieldAccess(Entity<?> entity, long id, MapField<K, V> field) {
    }

    @Override
    protected <E> QueryList<E> doListFieldAccess(Entity<?> entity, long id, ListField<E> field) {
    }

    @Override
    protected <E> QuerySet<E> doIndexAccess(Entity<?> entity, long id, Index<E> index, Object... values) {
    }
}

